/**
 *
 * This Class contains alle basic techniques/methods for the AI.
 * Tt's also the core for the valuation regulation for the alpha-beta pruning
 */
package AIEngine;

public class BasicAI {

	/**
	 * Shows if a cell in a array is empty
	 * @param cell <=> array[x][y]
	 * @return true if the cell is empty otherwise false
	 */
	public static boolean isEmpty(int cell) {
		if (Math.abs(cell) != 1) {
			return true;
		} else {
			return false;
		}
	}


	static long getFullValue(long value, boolean black, long nodeDepth) {
		if (black && nodeDepth%2==0) {
			return value * -1;
		}
		if (!black && nodeDepth%2!=0){
			return value * -1;
		}
		
		return value;
	}

	
	
	public static long searchTwoInARow(int[][] field) {
		long value = 0;
		int weight = 3;
		
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 5; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1])) {

					if (j < 4 && j > 0 ){
						if(isEmpty(field[i][j - 1])) {
							value += weight * field[i][j];
						}
						if(isEmpty(field[i][j + 2])) {
							value += weight * field[i][j];
						}
					} else {
						if (j==0 && isEmpty(field[i][j + 2])) {
							value += weight * field[i][j]; 
						}
						if ((j==4) && isEmpty(field[i][j - 1])) {
							value += weight * field[i][j];
						}
					}

				}
			}
		}
		return value;
	}
	
	
	
	
	public static long searchTwoInAColumn(int[][] field) {
		long value = 0;
		int weight = 3;

		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 6; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j])) {

					if (i < 4 && i > 0){
						if(isEmpty(field[i - 1][j])) {
							value += weight * field[i][j];
						}
						if(isEmpty(field[i + 2][j])) {
							value += weight * field[i][j];
						}
					} else {
						if (i==0 && isEmpty(field[i + 2][j])) {
							value += weight * field[i][j]; 
						}
						if (i==4 && isEmpty(field[i - 1][j])) {
							value += weight * field[i][j];
						}
					}
				}
			}
		}

		return value;
	}
	
	
	
	public static long searchTwoInADiagonal(int[][] field) {
		long value = 0;
		int weight_main = 3;
		int weight_second = 3;
		
		for(int j = 0 ; j < 5 ; j++){
			for(int i = 0 ; i < 5 ; i++){
				if(i>0 && i<4 && j>0 && j<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i+2][j+2])) {
						value += weight_main * field[i][j];
					}
					if (isEmpty(field[i-1][j-1])) {
						value += weight_main * field[i][j];
					}
				}
				
				if(i==0 && j<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i+2][j+2])) {
						value += weight_main * field[i][j];
					}
				}
				
				if(i==4 && j>0 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i-1][j-1])) {
						value += weight_main * field[i][j];
					}
				}
				
				if(j==0 && i<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i+2][j+2])) {
						value += weight_main * field[i][j];
					}
				}
				
				if(j==4 && i>0 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i-1][j-1])) {
						value += weight_main * field[i][j];
					}
				}
			}
		}
		
		for(int j = 5 ; j > 0; j--){
			for(int i = 0 ; i < 5 ; i++){
				if(i>0 && i<4 && j>1 && j<5 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i+2][j-2])) {
						value += weight_second * field[i][j];
					}
					if (isEmpty(field[i-1][j+1])) {
						value += weight_second * field[i][j];
					}
				}
				
				if(i==0 && j>1 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i+2][j-2])) {
						value += weight_second * field[i][j];
					}
				}
				
				if(i==4 && j<5 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i-1][j+1])) {
						value += weight_second * field[i][j];
					}
				}
				
				if(j==1 && i>0 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i-1][j+1])) {
						value += weight_second * field[i][j];
					}
				}
				
				if(j==5 && i<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i+2][j-2])) {
						value += weight_second * field[i][j];
					}
				}
			}
		}
		
		
		return value;
	}
	
	
	
	
	public static long searchTwoOverThreeInARow(int[][] field) {
		long value = 0;
		int weight = 3;
		
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 5; j++) {
				if ((j < 4)) {
					if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 2])) {
						if (isEmpty(field[i][j + 1])) {
							value += weight * field[i][j];                            
						}
					}
				}
			}
		}
		return value;
	}
	
	
	
	
	public static long searchTwoOverThreeInAColumn(int[][] field) {
		long value = 0;
		int weight = 3;
		
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 6; j++) {
				if (i < 4) {
					if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 2][j])) {
						if (isEmpty(field[i + 1][j])) {
							value += weight * field[i][j];
						}
					}
				}
			}
		}
		return value;
	}
	
	
	
	
	public static long searchTwoOverThreeInADiagonal(int[][] field) {
		long value = 0;
		int weight_main = 3;
		int weight_second = 3;
		
		for(int j = 0 ; j < 4 ; j++){
			for(int i = 0 ; i < 4 ; i++){
				if(Math.abs(field[i][j])==1 && field[i][j] == field[i+2][j+2]){
					if (isEmpty(field[i+1][j+1])) {
						value += weight_main * field[i][j];
					}
				}

			}
		}
		
		for(int j = 5 ; j > 1 ; j--){
			for(int i = 0 ; i < 4 ; i++){
				if(Math.abs(field[i][j])==1 && field[i][j] == field[i+2][j-2]){
					if (isEmpty(field[i+1][j-1])) {
						value += weight_second * field[i][j];
					}
				}

			}
		}

		return value;
	}
	

	public static long searchPossibleFourInARow(int[][] field) {
		long value = 0;
		int weight = 9;

		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 4; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 2])) {
					if (j==0 && isEmpty(field[i][j + 3]) && isEmpty(field[i][j + 4])){
						value += weight * field[i][j];
					}
					
					if (j==1) {
						if(isEmpty(field[i][j - 1]) && isEmpty(field[i][j + 3])){
							value += weight * field[i][j];
						}
						if (isEmpty(field[i][j + 3]) && isEmpty(field[i][j + 4])){
						value += weight * field[i][j];
						}
					}
					
					if (j==2) {
						if(isEmpty(field[i][j - 2]) && isEmpty(field[i][j - 1])){
							value += weight * field[i][j];
						}
						if (isEmpty(field[i][j - 1]) && isEmpty(field[i][j + 3])){
							value += weight * field[i][j];
						}
					}
					
					if (j==3 && ((isEmpty(field[i][j - 2]) && isEmpty(field[i][j - 1])))){
						value += weight * field[i][j];
					}

				}
			}
			
			for (int j = 0; j < 3; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 3])) {
					if (j==0 && isEmpty(field[i][j + 2]) && isEmpty(field[i][j + 4])){
						value += weight * field[i][j];
					}
					
					if (j==1) {
						if (isEmpty(field[i][j + 2]) && isEmpty(field[i][j - 1])) {
							value += weight * field[i][j];
						}
						if (isEmpty(field[i][j + 2]) && isEmpty(field[i][j + 4])){
							value += weight * field[i][j];
						}
					}
					
					if (j==2 && isEmpty(field[i][j + 2]) && isEmpty(field[i][j - 1])){
						value += weight * field[i][j];
					}
					
				}
				
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 2]) && (field[i][j + 2] == field[i][j + 3])) {
					if (j==0 && isEmpty(field[i][j + 1]) && isEmpty(field[i][j + 4])){
						value += weight * field[i][j];
					}
					if (j==1) {
						if (isEmpty(field[i][j + 1]) && isEmpty(field[i][j - 1])) {
						value += weight * field[i][j];
						}
						if(isEmpty(field[i][j + 1]) && isEmpty(field[i][j + 4])){
							value += weight * field[i][j];
						}
					}
					
					if (j==2 && isEmpty(field[i][j + 1]) && isEmpty(field[i][j - 1])) {
						value += weight * field[i][j];
					}
				}
			}
		}
		
		return value;
	}
	
	
	
	

	public static long searchPossibleFourInAColumn(int[][] field) {
		long value = 0;
		int weight = 9;
		
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 6; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 2][j])) {
					if (i==0 && isEmpty(field[i + 3][j]) && isEmpty(field[i + 4][j])){
						value += weight * field[i][j];
					}
					
					if (i==1) {
						if(isEmpty(field[i - 1][j]) && isEmpty(field[i + 3][j])){
							value += weight * field[i][j];
						}
						if (isEmpty(field[i + 3][j]) && isEmpty(field[i + 4][j])){
						value += weight * field[i][j];
						}
					}
					
					if (i==2) {
						if(isEmpty(field[i - 2][j]) && isEmpty(field[i -1][j])){
							value += weight * field[i][j];
						}
						if (isEmpty(field[i - 1][j]) && isEmpty(field[i + 3][j])){
							value += weight * field[i][j];
						}
					}
					
					if (i==3 && ((isEmpty(field[i - 2][j]) && isEmpty(field[i - 1][j])))){
						value += weight * field[i][j];
					}
				}
			}
		}

		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 6 ; j++){
				if((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 3][j])){
					if(i == 0){
						if((isEmpty(field[i + 2][j])) && (isEmpty(field[i + 4][j]))){
							value += weight * field[i][j];
						}
					}
					if(i == 1){
						if((isEmpty(field[i + 2][j])) && (isEmpty(field[i + 4][j]))) {
							value += weight * field[i][j];
						}
						if((isEmpty(field[i + 2][j])) && (isEmpty(field[i - 1][j]))) {
							value += weight * field[i][j];
						}
					}
					if(i == 2){
						if((isEmpty(field[i - 1][j])) && (isEmpty(field[i + 2][j]))){
							value += weight * field[i][j];
						}
					}

				}
				
				if((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 2][j]) && (field[i + 2][j] == field[i + 3][j])){	
					if(i == 0){
						if((isEmpty(field[i + 1][j])) && (isEmpty(field[i + 4][j]))){
							value += weight * field[i][j];
						}
					}
					if(i == 1){
						if((isEmpty(field[i - 1][j])) && (isEmpty(field[i + 1][j]))){
							value += weight * field[i][j];
						}
						if((isEmpty(field[i + 1][j])) && (isEmpty(field[i + 4][j]))){
							value += weight * field[i][j];
						}
					}
					if(i == 2){
						if((isEmpty(field[i - 1][j])) && (isEmpty(field[i + 1][j]))){
							value += weight * field[i][j];
						}
					}
					
				}
			}
		}
		return value;
	}

	
	
	
	

	public static long searchPossibleFourInDiagonal_TopLeft(int[][] field) {
		long value = 0;
		int weight = 9;

		// Analyzes principal diagonal
		for (int i = 0; i < 5; i++) {
			if (i!=2 && (Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (((Math.abs(field[1][1]) == 1) && field[i][i] == field[1][1]) && (Math.abs(field[4][4]) == 1) && field[i][i] == field[1][1])) {
				if (i == 0 && i == 4) {
					if (isEmpty(field[2][2]) && isEmpty(field[3][3])) {
						value += weight * field[i][i];
					}
				}
				else if (i == 1){
					if ((isEmpty(field[0][0]) && isEmpty(field[3][3]))){
						value += weight * field[i][i];
					}
					if (isEmpty(field[3][3]) && isEmpty(field[5][5])){
						value += weight * field[i][i];
					}
				}
				else if (i == 3){
					if ((isEmpty(field[0][0]) && isEmpty(field[2][2]))){
						value += weight * field[i][i];
					}
					if(isEmpty(field[2][2]) && isEmpty(field[5][5])){
						value += weight * field[i][i];
					}
				}
			}
		}

		
		// Analyzes diagonal under principal
		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[2][1]) && (field[1][0] == field[3][2])) {
			if (isEmpty(field[4][3]) && isEmpty(field[5][4])) {
				value += weight * field[1][0];
			}
		}
		
		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[2][1]) && (field[1][0] == field[4][3])) {
			if (isEmpty(field[3][2]) && isEmpty(field[5][4])) {
				value += weight * field[1][0];
			}
		}
		
		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[2][1]) && (field[1][0] == field[5][4])) {
			if (isEmpty(field[3][2]) && isEmpty(field[4][3])) {
				value += weight * field[1][0];
			}
		}
		
		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[3][2]) && (field[1][0] == field[4][3])) {
			if (isEmpty(field[2][1]) && isEmpty(field[5][4])) {
				value += weight * field[1][0];
			}
		}
		
		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[3][2]) && (field[1][0] == field[5][4])) {
			if (isEmpty(field[2][1]) && isEmpty(field[4][3])) {
				value += weight * field[1][0];
			}
		}
		
		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[4][3]) && (field[1][0] == field[5][4])) {
			if (isEmpty(field[2][1]) && isEmpty(field[3][2])) {
				value += weight * field[1][0];
			}
		}
		
		if ((Math.abs(field[2][1]) == 1) && (field[2][1] == field[3][2]) && (field[2][1] == field[4][3])) {
			if (isEmpty(field[1][0]) && isEmpty(field[5][4])) {
				value += weight * field[2][1];
			}
		}
		
		if ((Math.abs(field[2][1]) == 1) && (field[2][1] == field[3][2]) && (field[2][1] == field[5][4])) {
			if (isEmpty(field[1][0]) && isEmpty(field[4][3])) {
				value += weight * field[2][1];
			}
		}
		
		if ((Math.abs(field[2][1]) == 1) && (field[2][1] == field[4][3]) && (field[2][1] == field[5][4])) {
			if (isEmpty(field[1][0]) && isEmpty(field[3][2])) {
				value += weight * field[2][1];
			}
		}
		
		if ((Math.abs(field[3][2]) == 1) && (field[3][2] == field[4][3]) && (field[3][2] == field[5][4])) {
			if (isEmpty(field[1][0]) && isEmpty(field[2][1])) {
				value += weight * field[3][2];
			}
		}
		
		
		
		
		
		// Analyzes diagonal over principal
		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[1][2]) && (field[0][1] == field[2][3])) {
			if (isEmpty(field[3][4]) && isEmpty(field[4][5])) {
				value += weight * field[0][1];
			}
		}
		
		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[1][2]) && (field[0][1] == field[3][4])) {
			if (isEmpty(field[2][3]) && isEmpty(field[4][5])) {
				value += weight * field[0][1];
			}
		}
		
		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[2][3]) && (field[0][1] == field[3][4])) {
			if (isEmpty(field[1][2]) && isEmpty(field[4][5])) {
				value += weight * field[0][1];
			}
		}
		
		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[2][3]) && (field[0][1] == field[4][5])) {
			if (isEmpty(field[1][2]) && isEmpty(field[3][4])) {
				value += weight * field[0][1];
			}
		}
		
		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[3][4]) && (field[0][1] == field[4][5])) {
			if (isEmpty(field[1][2]) && isEmpty(field[2][3])) {
				value += weight * field[0][1];
			}
		}
		
		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[1][2]) && (field[0][1] == field[4][5])) {
			if (isEmpty(field[2][3]) && isEmpty(field[3][4])) {
				value += weight * field[0][1];
			}
		}
		
		if ((Math.abs(field[1][2]) == 1) && (field[1][2] == field[2][3]) && (field[1][2] == field[3][4])) {
			if (isEmpty(field[0][1]) && isEmpty(field[4][5])) {
				value += weight * field[1][2];
			}
		}
		
		if ((Math.abs(field[1][2]) == 1) && (field[1][2] == field[2][3]) && (field[1][2] == field[4][5])) {
			if (isEmpty(field[0][1]) && isEmpty(field[3][4])) {
				value += weight * field[1][2];
			}
		}
		if ((Math.abs(field[1][2]) == 1) && (field[1][2] == field[3][4]) && (field[1][2] == field[4][5])) {
			if (isEmpty(field[0][1]) && isEmpty(field[2][3])) {
				value += weight * field[1][2];
			}
		}
		
		if ((Math.abs(field[2][3]) == 1) && (field[2][3] == field[3][4]) && (field[2][3] == field[4][5])) {
			if (isEmpty(field[0][1]) && isEmpty(field[1][2])) {
				value += weight * field[2][3];
			}
		}

		return value;
	}
	
	public static long searchPossibleFourInDiagonal_BelowLeft(int[][] field) {
		long value = 0;
		int weight = 9;

		// Analyzes secundary diagonal
		for (int i = 0, j = 5; i < 5 && j > 0; i++, j--) {
				if (i!=2 && (Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j - 1]) && (((Math.abs(field[1][4]) == 1) && field[i][j] == field[1][4]) && (Math.abs(field[4][1]) == 1) && field[i][j] == field[4][1])) {
					if (i == 0 && i == 4) {
						if (isEmpty(field[2][3]) && isEmpty(field[3][2])) {
							value += weight * field[i][j];
						}
					} else if (i == 1) {
						if ((isEmpty(field[0][5]) && isEmpty(field[3][2]))) {
							value += weight * field[i][j];
						}
						if (isEmpty(field[3][2]) && isEmpty(field[5][0])){
							value += weight * field[i][j];
						}
					} else if (i == 3) {
						if ((isEmpty(field[2][3]) && isEmpty(field[5][0]))) {
							value += weight * field[i][j];
						}
						if (isEmpty(field[2][3]) && isEmpty(field[0][5])){
							value += weight * field[i][j];
						}
					}
				}
			}
		
		
		// Analyzes diagonal under secundary
		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[2][4]) && (field[1][5] == field[3][3])) {
			if (isEmpty(field[4][2]) && isEmpty(field[5][1])) {
				value += weight * field[1][5];
			}
		}
		
		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[2][4]) && (field[1][5] == field[4][2])) {
			if (isEmpty(field[3][3]) && isEmpty(field[5][1])) {
				value += weight * field[1][5];
			}
		}
		
		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[2][4]) && (field[1][5] == field[5][1])) {
			if (isEmpty(field[3][3]) && isEmpty(field[4][2])) {
				value += weight * field[1][5];
			}
		}

		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[3][3]) && (field[1][5] == field[4][2])) {
			if (isEmpty(field[2][4]) && isEmpty(field[5][1])) {
				value += weight * field[1][5];
			}
		}
		
		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[3][3]) && (field[1][5] == field[5][1])) {
			if (isEmpty(field[2][4]) && isEmpty(field[4][2])) {
				value += weight * field[1][5];
			}
		}
		
		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[4][2]) && (field[1][5] == field[5][1])) {
			if (isEmpty(field[2][4]) && isEmpty(field[3][3])) {
				value += weight * field[1][5];
			}
		}

		if ((Math.abs(field[2][4]) == 1) && (field[2][4] == field[3][3]) && (field[2][4] == field[4][2])) {
			if (isEmpty(field[1][5]) && isEmpty(field[5][1])) {
				value += weight * field[2][4];
			}
		}
		
		if ((Math.abs(field[2][4]) == 1) && (field[2][4] == field[3][3]) && (field[2][4] == field[5][1])) {
			if (isEmpty(field[1][5]) && isEmpty(field[4][2])) {
				value += weight * field[2][4];
			}
		}
		
		if ((Math.abs(field[2][4]) == 1) && (field[2][4] == field[4][2]) && (field[2][4] == field[5][1])) {
			if (isEmpty(field[1][5]) && isEmpty(field[3][3])) {
				value += weight * field[2][4];
			}
		}
		
		if ((Math.abs(field[3][3]) == 1) && (field[3][3] == field[4][2]) && (field[3][3] == field[5][1])) {
			if (isEmpty(field[1][5]) && isEmpty(field[2][4])) {
				value += weight * field[3][3];
			}
		}

		
		// Analyzes diagonal over secundary
		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[1][3]) && (field[0][4] == field[2][2])) {
			if (isEmpty(field[3][1]) && isEmpty(field[4][0])) {
				value += weight * field[0][4];
			}
		}
		
		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[1][3]) && (field[0][4] == field[3][1])) {
			if (isEmpty(field[2][2]) && isEmpty(field[4][0])) {
				value += weight * field[0][4];
			}
		}
		
		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[1][3]) && (field[0][4] == field[4][0])) {
			if (isEmpty(field[2][2]) && isEmpty(field[3][1])) {
				value += weight * field[0][4];
			}
		}
		
		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[2][2]) && (field[0][4] == field[3][1])) {
			if (isEmpty(field[1][3]) && isEmpty(field[4][0])) {
				value += weight * field[0][4];
			}
		}
		
		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[2][2]) && (field[0][4] == field[4][0])) {
			if (isEmpty(field[1][3]) && isEmpty(field[3][1])) {
				value += weight * field[0][4];
			}
		}
		
		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[3][1]) && (field[0][4] == field[4][0])) {
			if (isEmpty(field[1][3]) && isEmpty(field[2][2])) {
				value += weight * field[0][4];
			}
		}
			
		if ((Math.abs(field[1][3]) == 1) && (field[1][3] == field[2][2]) && (field[1][3] == field[3][1])) {
			if (isEmpty(field[0][4]) && isEmpty(field[4][0])) {
				value += weight * field[1][3];
			}
		}
		
		if ((Math.abs(field[1][3]) == 1) && (field[1][3] == field[2][2]) && (field[1][3] == field[4][0])) {
			if (isEmpty(field[0][4]) && isEmpty(field[3][1])) {
				value += weight * field[1][3];
			}
		}
		
		if ((Math.abs(field[1][3]) == 1) && (field[1][3] == field[3][1]) && (field[1][3] == field[4][0])) {
			if (isEmpty(field[0][4]) && isEmpty(field[2][2])) {
				value += weight * field[1][3];
			}
		}
		
		if ((Math.abs(field[2][2]) == 1) && (field[2][2] == field[3][1]) && (field[2][2] == field[4][0])) {
			if (isEmpty(field[0][4]) && isEmpty(field[1][3])) {
				value += weight * field[2][2];
			}
		}

		return value;
	}


	
	
	

	public static long searchPossibleFiveInARow(int[][] field) {
		long value = 0;
		int weight = 300;

		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 3; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 2]) && (field[i][j + 1] == field[i][j + 3])) {
					if (j==0 && isEmpty(field[i][j + 4])){
						value += weight * field[i][j];
					}
					
					if (j==1) {
						if(isEmpty(field[i][j - 1])){
							value += weight * field[i][j];
						}
						if (isEmpty(field[i][j + 4])){
						value += weight * field[i][j];
						}
					}
					
					if (j==2) {
						if(isEmpty(field[i][j - 1])){
							value += weight * field[i][j];
						}
					}
				}
			}
		}
		
		for(int i=0; i<5; i++){
			if((Math.abs(field[i][0]) == 1) && (field[i][0] == field[i][1]) && (field[i][0] == field[i][2]) && (field[i][0] == field[i][4])){
				if(isEmpty(field[i][3])){
					value += weight * field[i][0];
				}
			}
			
			if((Math.abs(field[i][0]) == 1) && (field[i][0] == field[i][1]) && (field[i][0] == field[i][3]) && (field[i][0] == field[i][4])){
				if(isEmpty(field[i][2])){
					value += weight * field[i][0];
				}
			}
			
			if((Math.abs(field[i][0]) == 1) && (field[i][0] == field[i][2]) && (field[i][0] == field[i][3]) && (field[i][0] == field[i][4])){
				if(isEmpty(field[i][1])){
					value += weight * field[i][0];
				}
			}
			
			if((Math.abs(field[i][1]) == 1) && (field[i][1] == field[i][2]) && (field[i][1] == field[i][3]) && (field[i][1] == field[i][5])){
				if(isEmpty(field[i][4])){
					value += weight * field[i][1];
				}
			}
			
			if((Math.abs(field[i][1]) == 1) && (field[i][1] == field[i][2]) && (field[i][1] == field[i][4]) && (field[i][1] == field[i][5])){
				if(isEmpty(field[i][3])){
					value += weight * field[i][1];
				}
			}
			
			if((Math.abs(field[i][1]) == 1) && (field[i][1] == field[i][3]) && (field[i][1] == field[i][4]) && (field[i][1] == field[i][5])){
				if(isEmpty(field[i][2])){
					value += weight * field[i][1];
				}
			}
		}
		
		return value;
	}

	public static long searchPossibleFiveInAColumn(int[][] field) {
		long value = 0;
		int weight = 300;

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 6; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 2][j]) && (field[i + 1][j] == field[i + 3][j])) {
					if (i==0 && isEmpty(field[i  + 4][j])){
						value += weight * field[i][j];
					}
					
					if (i==1) {
						if(isEmpty(field[i - 1][j])){
							value += weight * field[i][j];
						}
						if (isEmpty(field[i + 4][j])){
						value += weight * field[i][j];
						}
					}
					
					if (i==2) {
						if(isEmpty(field[i - 1][j])){
							value += weight * field[i][j];
						}
					}
				}
			}
		}
		
		for(int j = 0; j < 5; j++){
			if((Math.abs(field[0][j]) == 1) && (field[0][j] == field[1][j]) && (field[0][j] == field[2][j]) && (field[0][j] == field[4][j])){
				if(isEmpty(field[3][j])){
					value += weight * field[0][j];
				}
			}
			
			if((Math.abs(field[0][j]) == 1) && (field[0][j] == field[1][j]) && (field[0][j] == field[3][j]) && (field[0][j] == field[4][j])){
				if(isEmpty(field[2][j])){
					value += weight * field[0][j];
				}
			}
			
			if((Math.abs(field[0][j]) == 1) && (field[0][j] == field[2][j]) && (field[0][j] == field[3][j]) && (field[0][j] == field[4][j])){
				if(isEmpty(field[1][j])){
					value += weight * field[0][j];
				}
			}
			
			if((Math.abs(field[1][j]) == 1) && (field[1][j] == field[2][j]) && (field[1][j] == field[3][j]) && (field[1][j] == field[5][j])){
				if(isEmpty(field[4][j])){
					value += weight * field[1][j];
				}
			}
			
			if((Math.abs(field[1][j]) == 1) && (field[1][j] == field[2][j]) && (field[1][j] == field[4][j]) && (field[1][j] == field[5][j])){
				if(isEmpty(field[3][j])){
					value += weight * field[1][j];
				}
			}
			
			if((Math.abs(field[1][j]) == 1) && (field[1][j] == field[3][j]) && (field[1][j] == field[4][j]) && (field[1][j] == field[5][j])){
				if(isEmpty(field[2][j])){
					value += weight * field[1][j];
				}
			}
		}
		return value;
	}
	

	public static long searchPossibleFiveInADiagonal_TopLeft(int[][] field) {
		long value = 0;
		int weight = 300;
		
		for(int i = 0; i < 3; i++){
			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (field[i + 1][i + 1] == field[i + 2][i + 2]) && (field[i + 2][i + 2] == field[i + 3][i + 3])){
				if(i==0 && isEmpty(field[i + 4][i + 4])){
					value += weight * field[i][i];
				}
			
				if(i==1) {
					if(isEmpty(field[i - 1][i - 1])){
						value += weight * field[i][i];
					}
					if(isEmpty(field[i + 4][i + 4])){
						value += weight * field[i][i];
					}
				}
			
				if(i==2 && (isEmpty(field[i - 1][i - 1]))){
					value += weight * field[i][i];
				}
			}
		}
		
		for(int i = 0; i < 2; i++){
			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 2][i + 2]) && (field[i + 2][i + 2] == field[i + 3][i + 3]) && (field[i + 3][i + 3] == field[i + 4][i + 4])){
				if(isEmpty(field[i + 1][i + 1])){
					value += weight * field[i][i];
				}
			}
			
			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (field[i + 1][i + 1] == field[i + 3][i + 3]) && (field[i + 3][i + 3] == field[i + 4][i + 4])){
				if(isEmpty(field[i + 2][i + 2])){
					value += weight * field[i][i];
				}
			}
			
			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (field[i + 1][i + 1] == field[i + 2][i + 2]) && (field[i + 2][i + 2] == field[i + 4][i + 4])){
				if(isEmpty(field[i + 3][i + 3])){
					value += weight * field[i][i];
				}
			}
		}
		
		return value;
	}

	
	
	
	public static long searchPossibleFiveInADiagonal_BelowLeft(int[][] field) {
		long value = 0;
		int weight = 300;
		
		/* 4 marble allineati sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[4][1]) && (field[4][1] == field[3][2]) && (field[3][2] == field[2][3])){
			if(isEmpty(field[1][4])){
				value += weight * field[5][0];
			}
		}
		
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[3][2]) && (field[3][2] == field[2][3]) && (field[2][3] == field[1][4])){
			if(isEmpty(field[5][0])){
				value += weight * field[4][1];
			}
			if(isEmpty(field[0][5])){
				value += weight * field[4][1];
			}
		}
		
		if((Math.abs(field[3][2]) == 1) && (field[3][2] == field[2][3]) && (field[2][3] == field[1][4]) && (field[1][4] == field[0][5])){
			if(isEmpty(field[4][1])){
				value += weight * field[3][2];
			}
		}
		
		/* 1 marble + spazio + 3 marble allineati sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[3][2]) && (field[3][2] == field[2][3]) && (field[2][3] == field[1][4])){
			if(isEmpty(field[4][1])){
				value += weight * field[5][0];
			}
		}
		
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[2][3]) && (field[2][3] == field[1][4]) && (field[1][4] == field[0][5])){
			if(isEmpty(field[3][2])){
				value += weight * field[4][1];
			}
		}
		
		/* 2 marble allineati + spazio + 2 marble allineati sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[4][1]) && (field[4][1] == field[2][3]) && (field[2][3] == field[1][4])){
			if(isEmpty(field[3][2])){
				value += weight * field[5][0];
			}
		}
		
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[3][2]) && (field[3][2] == field[1][4]) && (field[1][4] == field[0][5])){
			if(isEmpty(field[2][3])){
				value += weight * field[4][1];
			}
		}
		
		/* 3 marble allineati + spazio + 1 marble sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[4][1]) && (field[4][1] == field[3][2]) && (field[3][2] == field[1][4])){
			if(isEmpty(field[2][3])){
				value += weight * field[5][0];
			}
		}
		
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[3][2]) && (field[3][2] == field[2][3]) && (field[2][3] == field[0][5])){
			if(isEmpty(field[1][4])){
				value += weight * field[4][1];
			}
		}
		return value;
	}
	


	public static long searchPossibleFiveInADiagonal_TopLeft_UnderUpperMain(int[][] field) {
		long value = 0;
		int weight = 300;
		
		/** Controllo elementi sopra la diagonale principale **/
		if(isEmpty(field[0][1]) && Math.abs(field[1][2])==1 && field[1][2]==field[2][3] && field[1][2]==field[3][4] && field[1][2] == field[4][5]){
			value+= weight*field[1][2]; // primo elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[1][2]) && Math.abs(field[0][1])==1 && field[0][1]==field[2][3] && field[0][1]==field[3][4] && field[0][1]==field[4][5]){
			value+= weight*field[0][1]; //secondo elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[2][3]) && Math.abs(field[0][1])==1 && field[0][1]==field[1][2] && field[0][1]==field[3][4] && field[0][1]==field[4][5]){
			value+= weight*field[0][1]; //terzo elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[3][4]) && Math.abs(field[0][1])==1 && field[0][1]==field[1][2] && field[0][1]==field[2][3] && field[0][1]==field[4][5]){
			value+= weight*field[0][1]; //quarto elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[4][5]) && Math.abs(field[0][1])==1 && field[0][1]==field[1][2] && field[0][1]==field[2][3] && field[0][1]==field[3][4]){
			value+= weight*field[0][1]; //quinto elemento libero sulla diagonale sopra la principale
		}
		
		/** Controllo elementi sotto la diagonale principale **/
		
		if(isEmpty(field[1][0]) && Math.abs(field[2][1])==1 && field[2][1]==field[3][2] && field[2][1]==field[4][3] && field[2][1] == field[5][4]){
			value+= weight*field[2][1]; // primo elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[2][1]) && Math.abs(field[1][0])==1 && field[1][0]==field[3][2] && field[1][0]==field[4][3] && field[1][0]==field[5][4]){
			value+= weight*field[1][0]; //secondo elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[3][2]) && Math.abs(field[1][0])==1 && field[1][0]==field[2][1] && field[1][0]==field[4][3] && field[1][0]==field[5][4]){
			value+= weight*field[1][0]; //terzo elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[4][3]) && Math.abs(field[1][0])==1 && field[1][0]==field[2][1] && field[1][0]==field[3][2] && field[1][0]==field[5][4]){
			value+= weight*field[1][0]; //quarto elemento libero sulla diagonale sopra la principale
		}
		
		if(isEmpty(field[5][4]) && Math.abs(field[1][0])==1 && field[1][0]==field[2][1] && field[1][0]==field[3][2] && field[1][0]==field[4][3]){
			value+= weight*field[1][0]; //quinto elemento libero sulla diagonale sopra la principale
		}
		return value;
	}
	

	



	public static long searchPossibleFiveInADiagonal_BelowLeft_UnderUpperMain(int[][] field) {
		long value = 0;
		int weight = 300;
		
		/**Controllo elementi sotto la diagonale secondaria**/
		if(isEmpty(field[5][1]) && Math.abs(field[4][2])==1 && field[4][2]==field[3][3] && field[4][2]==field[2][4] && field[4][2]==field[1][5]){
			value+= weight*field[4][2]; // primo elemento libero sulla diagonale sopra la secondaria
		}
		
		if(isEmpty(field[4][2]) && Math.abs(field[5][1])==1 && field[5][1]==field[3][3] && field[5][1]==field[2][4] && field[5][1]==field[1][5]){
			value+= weight*field[5][1]; //secondo elemento libero sulla diagonale sopra la secondaria
		}
		
		if(isEmpty(field[3][3]) && Math.abs(field[5][1])==1 && field[5][1]==field[4][2] && field[5][1]==field[2][4] && field[5][1]==field[1][5]){
			value+= weight*field[5][1]; //terzo elemento libero sulla diagonale sopra la secondaria
		}
		
		if(isEmpty(field[2][4]) && Math.abs(field[5][1])==1 && field[5][1]==field[4][2] && field[5][1]==field[3][3] && field[5][1]==field[1][5]){
			value+= weight*field[5][1]; //quarto elemento libero sulla diagonale sopra la secondaria
		}
		
		if(isEmpty(field[1][5]) && Math.abs(field[5][1])==1 && field[5][1]==field[4][2] && field[5][1]==field[3][3] && field[5][1]==field[2][4]){
			value+= weight*field[5][1]; //quinto elemento libero sulla diagonale sopra la secondaria
		}
		
		/**Controllo elementi sopra la diagonale secondaria**/
		if(isEmpty(field[0][4]) && Math.abs(field[1][3])==1 && field[1][3]==field[2][2] && field[1][3]==field[3][1] && field[1][3]==field[4][0]){
			value+= weight*field[1][3]; // primo elemento libero sulla diagonale sotto la secondaria
		}
		
		if(isEmpty(field[1][3]) && Math.abs(field[0][4])==1 && field[0][4]==field[2][2] && field[0][4]==field[3][1] && field[0][4]==field[4][0]){
			value+= weight*field[0][4]; //secondo elemento libero sulla diagonale sotto la secondaria
		}
		
		if(isEmpty(field[2][2]) && Math.abs(field[0][4])==1 && field[0][4]==field[1][3] && field[0][4]==field[3][1] && field[0][4]==field[4][0]){
			value+= weight*field[0][4]; //terzo elemento libero sulla diagonale sotto la secondaria
		}
		
		if(isEmpty(field[3][1]) && Math.abs(field[0][4])==1 && field[0][4]==field[1][3] && field[0][4]==field[2][2] && field[0][4]==field[4][0]){
			value+= weight*field[0][4]; //quarto elemento libero sulla diagonale sotto la secondaria
		}
		
		if(isEmpty(field[4][0]) && Math.abs(field[0][4])==1 && field[0][4]==field[1][3] && field[0][4]==field[3][1] && field[0][4]==field[2][2]){
			value+= weight*field[0][4]; //quinto elemento libero sulla diagonale sotto la secondaria
		}
		
		return value;
	}
	
	
	
	
	public static long fullJudge(int[][] field, boolean black, long nodeDepth, int turnsLeft, int limit) {
		long value = 0;

		if (turnsLeft > limit) {
			// Possibili 3
			value += searchTwoInARow(field);
			value += searchTwoInAColumn(field);
			value += searchTwoInADiagonal(field);
			value += searchTwoOverThreeInARow(field);
			value += searchTwoOverThreeInAColumn(field);
			value += searchTwoOverThreeInADiagonal(field);

			// Possibili 4
			value += searchPossibleFourInARow(field);
			value += searchPossibleFourInAColumn(field);
			value += searchPossibleFourInDiagonal_TopLeft(field);
			value += searchPossibleFourInDiagonal_BelowLeft(field);

			// Possibili 5
			value += searchPossibleFiveInARow(field);
			value += searchPossibleFiveInAColumn(field);
			value += searchPossibleFiveInADiagonal_TopLeft(field);
			value += searchPossibleFiveInADiagonal_TopLeft_UnderUpperMain(field);
			value += searchPossibleFiveInADiagonal_BelowLeft(field);
			value += searchPossibleFiveInADiagonal_BelowLeft_UnderUpperMain(field);
		}

		if (BasicAI.checkWin(field, true)) {
			value = -99999;
		}

		if (BasicAI.checkWin(field, false)) {
			value = 99999;
		}
		
		if (BasicAI.checkWin(field, false) && BasicAI.checkWin(field, true)) {
			value = 0;
		}

		value = getFullValue(value, black, nodeDepth);

		return value;
	}

	
	

	/**
	 * A modified version of the rotate method from the GameEngine.Board
	 * 
	 * see GameEngine.Board.rotate
	 *
	 * @param board current array
	 * @param quadrant which is supposed to be rotated
	 * @param clock true for a right rotation, false for a left retation
	 * @return new rotated board
	 */
	public static int[][] rotate(int[][] board, int quadrant, int clock) {
		boolean clockwise = false;
		int[][] rotatedBoard = new int[6][6];
		int[][] singleQuadranRotatedBoard = new int[6][6];
		int startX=0, startY=0, endX = 0, endY=0, clockwiseRotation=0, counterClockWise=0, counterClockWiseRefresh=0, rotatingCol=0;

		fill(board, rotatedBoard);

		if(clock==1){
			clockwise = true;
		}

		//setting parameters sub rotation
		if(quadrant == 1){
			clockwiseRotation=0;
			counterClockWise=0;
			counterClockWiseRefresh=0;
			rotatingCol=3;
			startX=0;
			startY=0;
			endX=3;
			endY=3;
		}else if (quadrant==2){
			clockwiseRotation=3;
			counterClockWise=0;
			counterClockWiseRefresh=0;
			rotatingCol=6;
			startX=0;
			startY=3;
			endX=3;
			endY=6;
		}else if (quadrant==3){
			clockwiseRotation=0;
			counterClockWise=3;
			counterClockWiseRefresh=3;
			rotatingCol=6;
			startX=3;
			startY=0;
			endX=6;
			endY=3;
		}else{
			clockwiseRotation=3;
			counterClockWise=3;
			counterClockWiseRefresh=3;
			rotatingCol=9;
			startX=3;
			startY=3;
			endX=6;
			endY=6;
		}

		if(clockwise){
			for (int i = startX; i < endX; ++i) {
				for (int j = startY; j < endY; ++j) {
					singleQuadranRotatedBoard[i][j] = rotatedBoard[rotatingCol - j - 1][clockwiseRotation];
				}
				clockwiseRotation++;
			}

		}else{
			for (int i = startX; i < endX; ++i) {
				for (int j = startY; j < endY; ++j) {
					singleQuadranRotatedBoard[i][j] = rotatedBoard[counterClockWise][rotatingCol - i - 1];
					counterClockWise++;
				}
				counterClockWise=counterClockWiseRefresh;
			}
		}

		for (int i = startX; i < endX; ++i) {
			for (int j = startY; j < endY; ++j) {
				rotatedBoard[i][j] = singleQuadranRotatedBoard[i][j];
			}
		}

		return rotatedBoard;
	}

	
	/**
	 * This method copys on cell from a array into an other,
	 *
	 * @param field
	 * @param tofillup
	 */
	public static void fill(int[][] field, int[][] tofillup) {
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 6; j++) {
				tofillup[i][j] = field[i][j];
			}
		}
	}


	



	/**
	 * Shows if the player flag who got a winning situation in a Column
	 * @param board
	 * @param who
	 * @return boolean if win = true else false
	 */
	public static boolean checkWinColumn(int[][] board, boolean who) {

		int temp = 1;
		if(who)
			temp = -1;
		for (int i = 0; i < 6; i++) {
			/*initialize sum with 0*/
			int sum = 0;
			for (int j = 0; j < 6; j++) {
					if (board[j][i] == temp) {
						sum += board[j][i];
					} else {
						sum = 0;
					}
					if (Math.abs(sum) == 5) {
						return true;
					}
			}
		}
		return false;
	}

	
	/**
	 * This function calculates the sum of the rows
	 * @param who This parameter shows who is playing. If who = true, Black plays, else White plays
	 * @param board is the targetarray
	 * @return true if there is a wining situation on board
	 */
	public static boolean checkWinRow(int[][] board, boolean who) {

		int temp = 1;
		if(who)
			temp = -1;
		for (int i = 0; i < 6; i++) {
			/*initialize sum with 0*/
			int sum = 0;
			for (int j = 0; j < 6; j++) {
					if (board[i][j] == temp) {
						sum += board[i][j];
					} else {
						sum = 0;
					}
					if (Math.abs(sum) == 5) {
						return true;
					}
			}
		}
		return false;
	}

	
	/**
	 * This function calculates the sum of the 3 second diagonals
	 * @param who This parameter shows who is playing. If who = true, Black plays, else White plays
	 * @param board is the targetarray
	 * @return true if there is a wining situation on board
	 */
	public static boolean checkWinSecondDiag(int[][] board, boolean who) {
		
		int temp = 1;
		if(who)
			temp = -1;
		int sum = 0;
		/*Diagonal from 0|5 to 5|0*/
		for (int i = 0; i < 6; i++) {
			int j = 5 - i;
				if (board[j][i] == temp) {
					sum += board[j][i];
				} else {
					sum = 0;
				}
				if (Math.abs(sum) == 5) {
					return true;
				}
		}

		/*Diagonal from 0|4 to 4|0*/
		sum = 0;
		for (int i = 0; i < 5; i++) {
			int j = 4 - i;
				if (board[j][i] == temp) {
					sum += board[j][i];
				} else {
					sum = 0;
				}
				if (Math.abs(sum) == 5) {
					return true;
				}
		}

		/*Diagonal from 1|5 to 5|1*/
		sum = 0;
		for (int i = 1; i < 6; i++) {
			int j = 6 - i;
				if (board[i][j] == temp) {
					sum += board[i][j];
				} else {
					sum = 0;
				}
				if (Math.abs(sum) == 5) {
					return true;
				}
		}
		return false;

	}

	
	/**
	 * This function calculates the sum of the 3 diagonals
	 * @param who This parameter shows who is playing. If who = true, Black plays, else White plays
	 * @param board is the targetarray
	 * @return true if there is a wining situation on board
	 */
	public static boolean checkWinMainDiag(int[][] board, boolean who) {

		int temp = 1;
		if(who)
			temp = -1;
		/*Diagonal from 0|0 to 5|5*/

		/*initialize sum with 0*/
		int sum = 0;
		for (int i = 0; i < 6; i++) {

				if (board[i][i] == temp) {
					sum += board[i][i];
				} else {
					sum = 0;
				}
				if (Math.abs(sum) == 5) {
					return true;
				}
		}

		/*Diagonal from 0|1 to 4|5*/

		/*initialize sum with 0*/
		sum = 0;
		for (int i = 0; i < 5; i++) {

				if (board[i + 1][i] == temp) {
					sum += board[i + 1][i];
				} else {
					sum = 0;
				}
				if (Math.abs(sum) == 5) {
					return true;
				}
		}

		/*Diagonal from 1|0 to 5|4*/

		/*initialize sum with 0*/
		sum = 0;
		for (int i = 0; i < 5; i++) {

				if (board[i][i + 1] == temp) {
					sum += board[i][i + 1];
				} else {
					sum = 0;
				}
				if (Math.abs(sum) == 5) {
					return true;
				}
		}
		return false;

	}

	
	/**
	 * A modified version of the checkWin method from the GameEngine.Board
	 *
	 * @param board is the board that is supposed to be checked
	 * @param who palyerflag
	 * @return true if ther are 5 equal merbels in a row,column or diagnal oterwise false
	 */
	public static boolean checkWin(int[][] board, boolean who) {
		if (checkWinRow(board, who) == true) {
			return true;
		}

		if (checkWinColumn(board, who) == true) {
			return true;
		}

		if (checkWinMainDiag(board, who) == true) {
			return true;
		}

		if (checkWinSecondDiag(board, who) == true) {
			return true;
		}

		return false;
	}
}
